package com.thkj.modules.user.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thkj.modules.dao.BusinWorkerMapper;
import com.thkj.modules.dao.TemMeasuringMapper;
import com.thkj.modules.user.entity.BusinWorker;
import com.thkj.modules.user.entity.TemMeasuring;
import com.thkj.modules.user.service.TemMeasuringService;

import dp.service.BaseService;

@Service
public class TemMeasuringServiceImpl extends BaseService implements TemMeasuringService {

    @Autowired
    private TemMeasuringMapper temMeasuringMapper;

    @Autowired
    private BusinWorkerMapper businWorkerMapper;

    @Override
    public void insert(TemMeasuring temMeasuring) {
        temMeasuringMapper.insert(temMeasuring);
    }

    @Override
    public List<Map> queryByIndividualId(String individual_id, String timeStr) {
        List<Map> maps = businWorkerMapper.queryByIndividualId(individual_id, timeStr);
        return maps;
    }

    /**
     * 查询总数
     *
     * @param individual_id
     * @param type
     * @param timeStr
     * @return
     */
    public List<Map>  queryTotal(String individual_id, int type, String timeStr) {
        int workerCount = 0;
        int measuringCount = 0;
        int normalCount = 0;
        int abnormalCount = 0;

        BusinWorker businWorker = new BusinWorker();
        businWorker.setIndividualId(individual_id);
        workerCount = businWorkerMapper.selectCount(businWorker);
        if (type == 1) {
            measuringCount = temMeasuringMapper.queryByYearTotal(individual_id, null, timeStr);
            normalCount = temMeasuringMapper.queryByYearTotal(individual_id, 1, timeStr);
            abnormalCount = temMeasuringMapper.queryByYearTotal(individual_id, 2, timeStr);
        } else if (type == 2) {
            measuringCount = temMeasuringMapper.queryByMonthTotal(individual_id, null, timeStr);
            normalCount = temMeasuringMapper.queryByMonthTotal(individual_id, 1, timeStr);
            abnormalCount = temMeasuringMapper.queryByMonthTotal(individual_id, 2, timeStr);
        } else if (type == 3) {
            measuringCount = temMeasuringMapper.queryByDayTotal(individual_id, null, timeStr);
            normalCount = temMeasuringMapper.queryByDayTotal(individual_id, 1, timeStr);
            abnormalCount = temMeasuringMapper.queryByDayTotal(individual_id, 2, timeStr);
        } else if (type == 4) {
            measuringCount = temMeasuringMapper.queryByWeekTotal(individual_id, null, timeStr);
            normalCount = temMeasuringMapper.queryByWeekTotal(individual_id, 1, timeStr);
            abnormalCount = temMeasuringMapper.queryByWeekTotal(individual_id, 2, timeStr);
        }
        List<Map> list = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("员工总数("+workerCount+")", workerCount);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("体温测量总数("+measuringCount+")", measuringCount);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("体温正常总数("+normalCount+")", normalCount);
        Map<String, Object> map4 = new HashMap<>();
        map4.put("体温异常总数("+abnormalCount+")", abnormalCount);
        list.add(map1);
        list.add(map2);
        list.add(map3);
        list.add(map4);
        return list;
    }


}